package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.contractor.BpContractorCert;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author ZhangDong
 * @Date 2020/7/8 18:18
 */
public interface BpContractorCertDao extends JpaRepository<BpContractorCert, Long>, JpaSpecificationExecutor<BpContractorCert> {

    @Query("update BpContractorCert bc set bc.state=0 where bc.id=:id")
    @Modifying
    void contractorCertNullify(Long id);

    List<BpContractorCert> findByContractorIdAndState(Long contractorId, Integer state);

    @Query("select b from BpContractorCert b where b.state=1 and b.dutyScriptRemindOrNot=0 and b.certExpireDate is not null")
    List<BpContractorCert> findRemindTask();

    @Query("select b from BpContractorCert b where b.state=1 and b.dutyScriptRemindOrNot=0 and b.certExpireDate is not null " +
            "and b.contractorId=:contractorId")
    List<BpContractorCert> findRemindTaskAndContractorId(Long contractorId);
}
